<template>
  <view>
    <u-navbar :is-back="true" :is-fixed="true" title="品牌执法"></u-navbar>
    <scroll-view
      scroll-y
      scroll-with-animation
      style="height: calc(100vh - 50px)"
      :show-scrollbar="false"
    >
      <view class="mt-3 pl-2 pr-2">
        <view v-for="(item, itemIndex) in tabContents" :key="itemIndex">
          <view
            class="u-line pb-2 mt-1"
            @click="open('tabbar/index/brandEnforcementDi?id=' + item.id)"
          >
            <view class="dfex">
              <view>{{ item.enterpriseName }}</view>
              <view>{{ item.createTime }}</view>
            </view>
            <view class="mt-2 text-999999 font-12">{{
              item.enforcementInstructions
            }}</view>
          </view>
        </view>
      </view>
    </scroll-view>
  </view>
</template>

<script>
import $H from "@/common/free-lib/request.js";

export default {
  data() {
    return {
      tabContents: [],
      pageNo: 1,
      pageSize: 10,
    };
  },
  onLoad() {
    this.getBrandEnforcementList();
  },
  onPullDownRefresh() {
    this.tabContents = [];
    this.pageNo = 1;
    this.getBrandEnforcementList();
  },
  onReachBottom() {
    this.pageNo = this.pageNo + 1;
    this.getBrandEnforcementList();
  },
  methods: {
    open(path) {
      uni.navigateTo({
        url: "/pages/" + path,
      });
    },
    getBrandEnforcementList() {
      $H.get(
        "/agriculture/brandEnforcement/upper/list",
        {
          pageNo: this.pageNo,
          pageSize: this.pageSize,
        },
        {}
      )
        .then((res) => {
          if (res.result.records.length == 0) {
            uni.showToast({
              title: "没有更多啦！",
              icon: "success",
            });
            return;
          }
          let resList = [];
          for (let i = 0; i < res.result.records.length; i++) {
            const item = res.result.records[i];
            resList.push({
              enterpriseName: item.enterpriseName,
              enforcementInstructions: item.enforcementInstructions,
              createTime: item.createTime,
              id: item.id,
            });
          }
          this.tabContents = resList;
        })
        .catch((error) => {
          console.error("请求出错", error); // 处理任何错误
        });
    },
  },
};
</script>

<style>
</style>